#include <sys/types.h>
#include "../include/ohsm.h"
#include "ohsm_u.h"

int ohsm_enable_debug;

char relop_str[6][4] = { "<",">","==","!=","<=",">="};

struct ohsm_log_table_t ohsm_log_table[] = {
  OHSM_LOG_RELOCATE, "Relocate",
  OHSM_LOG_STATS,    "Stats",
  OHSM_LOG_GENERIC,  "Generic",
};

void
print_allocation_policy(struct ohsm_allocation_policy *allocpol)
{

	int i;

	printf("\nPrinting the allocation policy information");
	printf("\n==========================================");
	printf("\nNo. of policy based on UID = %d", allocpol->cnt_users);
	printf("\nNo. of policy based on GID = %d", allocpol->cnt_groups);
	printf("\nNo. of policy based on File Type = %d", allocpol->cnt_types);

	for (i = 0; i < allocpol->cnt_users; i++) {
		printf("\nUID = %d\tTier = %d",
			allocpol->uid_tier[i].uid, allocpol->uid_tier[i].tier);
	}
	for (i = 0; i < allocpol->cnt_groups; i++) {
		printf("\nGID = %d\tTier = %d",
			allocpol->gid_tier[i].gid, allocpol->gid_tier[i].tier);
	}
	for (i = 0; i < allocpol->cnt_types; i++) {
		printf("\nType = %3s\tTier = %d",
		   allocpol->type_tier[i].type, allocpol->type_tier[i].tier);
	}
	for (i = 0; i < allocpol->cnt_dirs; i++) {
		printf("\nDirs = %s\tTier = %d",
		   allocpol->dir_tier[i].dir_name, allocpol->dir_tier[i].tier);
	}
	printf("\n");
}


void
print_device_topology(struct ohsm_tier_dev_info *dev_info)
{

	int i;

	printf("\nPrinting the Tier Device map infomation");
	printf("\n=======================================");
	printf("\nTotal number of Tiers   = %u", dev_info->nr_tiers);
	printf("\nTotal mumber of Devices = %u", dev_info->nr_devices);

	for (i = 0; i < dev_info->dinfo_count; ++i) {
		if (!dev_info->device[i].tier)
			continue;
		printf("\nNo. %u.", i);
		printf("\tTier = %u ", dev_info->device[i].tier);
		printf("\tDevice = %u ", dev_info->device[i].dev_num);
		printf("\tLength = %lu ", dev_info->device[i].len);
		printf("\tStart  = %lu \n", dev_info->device[i].begin);
	}
}

void
print_relocation_policy(struct ohsm_reloc_policy *relocpol)
{

	int i = 0;

	printf("\nPrinting the relocation policy information");
	printf("\n==========================================");
	printf("\nNumber of Policies = %d", relocpol->cnt_policies);

	for (i = 0; i < relocpol->cnt_policies; i++) {
		printf("\n\nPolicy No. %d", i);
		printf("\nRelocation Criteria Bitmap = %x",
				relocpol->policy[i].reloc_criteria_bitmap);
		printf("\nFrom Tier = %d", relocpol->policy[i].src_tier);
		printf("\nTO Tier = %d", relocpol->policy[i].dest_tier);
		
		if (relocpol->policy[i].reloc_criteria_bitmap) 
			printf("\nWHEN");
		else
			printf("\nMOVE EVERYTHING");

		if (relocpol->policy[i].reloc_criteria_bitmap & 0x01) {
			printf("\nFSIZE  %s ", relop_str[relocpol->policy[i].rel_ops[0]]);
			printf("%lld KByte(s)", relocpol->policy[i].values[0]);
		}
		if (relocpol->policy[i].reloc_criteria_bitmap & 0x02) {
			printf(" && FAA %s ", relop_str[relocpol->policy[i].rel_ops[1]]);
			printf("%lld Day(s)", relocpol->policy[i].values[1]);
		}
		if (relocpol->policy[i].reloc_criteria_bitmap & 0x04) {
			printf(" && FMA %s ", relop_str[relocpol->policy[i].rel_ops[2]]);
			printf("%lld Day(s)", relocpol->policy[i].values[2]);
		}
		if (relocpol->policy[i].reloc_criteria_bitmap & 0x08) {
			printf(" && FIOT %s kb/sec", relop_str[relocpol->policy[i].rel_ops[3]]);
			printf("%lld", relocpol->policy[i].values[3]);
		}
		if (relocpol->policy[i].reloc_criteria_bitmap & 0x10) {
			printf(" && FAT %s ", relop_str[relocpol->policy[i].rel_ops[4]]);
			printf("%lld times/day", relocpol->policy[i].values[4]);
		}

	}
	printf("\n");
}
